package edu.umn.cs5115.scheduler.util;

import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

public final class WidgetUtil {
	/**
	 * Returns the number of expanded nodes in the tree
	 * 
	 * The number of expanded nodes is basically all the nodes you can see.
	 * 
	 * @param tree
	 * @return int number of expanded nodes in the tree
	 */
	public static int countTreeHeight(Tree tree) {
		int total = 0;
		
		for (int i = 0; i < tree.getItemCount(); i++) {
			TreeItem item = tree.getItem(i);
			total++;
			
			if (item.getExpanded()) total += item.getItemCount();
		}
		
		return total;
	}
}
